<template>
  <div>
    <footer class="footer">
      <span class="todo-count"
        ><strong>{{ list.length }}</strong
        >剩余</span
      >
      <ul class="filters">
        <li>
          <a
            href="#/"
            :class="{ selected: type === 'all' }"
            @click.prevent="type = 'all'"
            >全部</a
          >
        </li>
        <li>
          <a
            href="#/active"
            :class="{ selected: type === 'active' }"
            @click.prevent="type = 'active'"
            >进行中</a
          >
        </li>
        <li>
          <a
            href="#/completed"
            :class="{ selected: type === 'completed' }"
            @click.prevent="type = 'completed'"
            >已完成</a
          >
        </li>
      </ul>
      <button
        class="clear-completed"
        v-show="showClear"
        @click="$emit('clearList')"
      >
        清除已完成
      </button>
    </footer>
  </div>
</template>

<script>
export default {
  props: {
    list: {
      type: Array,
      required: true,
    },
  },
  data() {
    return {
      type: "all",
    };
  },
  methods: {},
  computed: {
    showClear() {
      return this.list.some((item) => {
        return item.isDone;
      });
    },
  },
  watch: {
    type(val) {
      this.$emit("changeType", val);
    },
  },
};
</script>

<style lang="scss" scoped>
</style>